<!--
 * @Author: wangshuixin 2412658453@qq.com
 * @Date: 2024-07-08 12:28:01
 * @LastEditors: wangshuixin 2412658453@qq.com
 * @LastEditTime: 2024-08-02 13:06:59
 * @FilePath: \web-components-box\components\Drawer\SideDrawer.vue
 * @Description: 侧边栏抽屉
-->
<script setup lang="ts">
const props = defineProps({
  visible: {
    type: Boolean,
    default: false,
  },
})
defineEmits(['closeDrawer'])
// 开启/关闭 抽屉（抽屉默认关闭）
const isDrawerOpen = computed(() => props.visible)
console.log(isDrawerOpen.value);

</script>

<template>
  <div class="relative">
    <a-modal :visible="isDrawerOpen" :width="0.01" :render-to-body="false" :footer="false" :closable="false" @cancel="$emit('closeDrawer', true)" />
    <div class="drawer" :class="{ 'drawer-open': isDrawerOpen }" @click.stop="">
      <div class="drawer-close" @click="$emit('closeDrawer', true)">
        <slot name="close">
          <icon-right />
        </slot>
      </div>
      <div>
        <slot name="content" />
      </div>
    </div>
  </div>
</template>

<style scoped lang="less">
// 抽屉 - 隐藏
.drawer {
  position: fixed;
  width: 990px;
  height: 100%;
  top: 0px;
  right: -1008px;
  background-color: white;
  transition: right .3s ease; /* 平滑过渡效果 */
  z-index: 1001; /* 高于覆盖层 */
  &-close {
    position: absolute;
    top: 120px;
    left: -18px;
    width: 36px;
    height: 36px;
    line-height: 36px;
    color: #C9CDD4;
    font-size: 16px;
    text-align: center;
    border-radius: 18px;
    background-color: white;
    border: 1px solid #F2F3F5;
    z-index: 1001;
  }
  &-close:hover {
    color: white;
    background-color: #8887FF;
    border: 1px solid #8887FF;
  }
}
// 抽屉 - 显示
.drawer-open {
  right: 0; /* 打开时移动到右侧 */
}
</style>